package com.woniuxy.rabbit;

import com.woniuxy.rabbit.config.MQConfig;
import com.woniuxy.rabbit.confirm.RegConfirmCallback;
import com.woniuxy.rabbit.form.UserRegMSG;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class App {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private RabbitTemplate.ConfirmCallback regConfirmCallback;

    @GetMapping("send")
    public String send(){
        UserRegMSG userRegMSG = new UserRegMSG();
        userRegMSG.setId(1);
        userRegMSG.setName("zhangsan");
        userRegMSG.setDate(new Date());
        rabbitTemplate.setConfirmCallback(regConfirmCallback);
        rabbitTemplate.convertAndSend(MQConfig.USER_EXCHANGE,MQConfig.USER_BINDING,userRegMSG
                ,new CorrelationData("666"));
        return "ok";
    }

}
